'use strict';

/**
 * @ngdoc function
 * @name consoleAngularUiApp.controller:loginCtrl
 * @description
 * # loginCtrl
 * Controller of the consoleAngularUiApp
 */
angular.module('consoleAngularUiApp')
  .controller('loginCtrl', ['$scope', '$authServ', function ($scope, $authServ) {
    	
    	$scope.login = function () {
    		$scope.errorNote = '';
			var isValid = $scope.loginForm.$valid;
    		if (isValid) {
    			doLogin();
    		}
    	}

    	function doLogin() {
    		$authServ.login($scope.username, $scope.password)
    					.success(function () {
    						var t = $authServ.token();

    					})
    					.error(function (res) {
    						$scope.errorNote = res['localization-key'];
    					});
    	}
  }]);
